package cloud.demarcia.yzcrawler;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;


@Component
@Slf4j
public class Starter implements CommandLineRunner {


    private final TaskManager taskManager;
    private final ApplicationContext applicationContext;

    @Autowired
    public Starter(TaskManager taskManager, ApplicationContext applicationContext) {
        this.taskManager = taskManager;
        this.applicationContext = applicationContext;
    }


    @Override
    public void run(String... args) {
        log.info("program started...");
        taskManager.run();
        log.info("program finished.");
        SpringApplication.exit(applicationContext);
    }
}
